package com.kede.app.rest;

import com.kede.annotation.Log;
import com.kede.app.domain.TransferLog;
import com.kede.app.service.TransferLogService;
import com.kede.app.service.dto.TransferLogQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @author Pr.li
* @date 2023-05-11
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "transferlog管理")
@RequestMapping("/api/transferLog")
public class TransferLogController {

    private final TransferLogService transferLogService;

    /**
     * 导出数据
     **/
    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('transferLog:list')")
    public void exportTransferLog(HttpServletResponse response, TransferLogQueryCriteria criteria) throws IOException {
        transferLogService.download(transferLogService.queryAll(criteria), response);
    }

    /**
    * 查询transferlog
    **/
    @GetMapping
    @Log("查询transferlog")
    @ApiOperation("查询transferlog")
    @PreAuthorize("@el.check('transferLog:list')")
    public ResponseEntity<Object> queryTransferLog(TransferLogQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(transferLogService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    /**
    * 新增transferlog
    **/
    @PostMapping
    @Log("新增transferlog")
    @ApiOperation("新增transferlog")
    @PreAuthorize("@el.check('transferLog:add')")
    public ResponseEntity<Object> createTransferLog(@Validated @RequestBody TransferLog resources){
        return new ResponseEntity<>(transferLogService.create(resources),HttpStatus.CREATED);
    }


    /**
    * 修改transferlog
    **/
    @PutMapping
    @Log("修改transferlog")
    @ApiOperation("修改transferlog")
    @PreAuthorize("@el.check('transferLog:edit')")
    public ResponseEntity<Object> updateTransferLog(@Validated @RequestBody TransferLog resources){
        transferLogService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }


    /**
    * 删除transferlog
    **/
    @DeleteMapping
    @Log("删除transferlog")
    @ApiOperation("删除transferlog")
    @PreAuthorize("@el.check('transferLog:del')")
    public ResponseEntity<Object> deleteTransferLog(@RequestBody Integer[] ids) {
        transferLogService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}